package service.jun.com.myservicedemo;

import android.app.Service;
import android.content.Intent;
import android.os.Binder;
import android.os.IBinder;
import android.support.annotation.Nullable;
import android.util.Log;

import java.util.Random;


/**
 * Created by jun on 2016/5/12.
 */
public class MyService extends Service {
    private static final String TAG = "MyService";
    private IBinder mBinder = new LocalBinder ();

    @Nullable
    @Override
    public IBinder onBind(Intent intent) {
        Log.e (TAG, "onBind: ");
        return mBinder;
    }


    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        Log.e (TAG, "onStartCommand: ");
        return super.onStartCommand (intent, flags, startId);
    }


    @Override
    public void onStart(Intent intent, int startId) {
        super.onStart (intent, startId);
        Log.e (TAG, "onStart: ");
    }

    @Override
    public void onDestroy() {
        super.onDestroy ();
        Log.e (TAG, "onDestroy: ");
    }


    @Override
    public boolean onUnbind(Intent intent) {
        Log.e (TAG, "onUnbind: ");
        return super.onUnbind (intent);
    }


    @Override
    public void onCreate() {
        super.onCreate ();
        Log.e (TAG, "onCreate: ");
    }

    @Override
    public boolean stopService(Intent name) {
        Log.e (TAG, "stopService: ");
        return super.stopService (name);
    }


    public class LocalBinder extends Binder {
        MyService getService() {
            return MyService.this;
        }
    }


    public int getRandom() {
        return new Random ().nextInt (1000);
    }

}
